package com.ht.web_vr_home_tour_backend.obj.pojo;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ht.web_vr_home_tour_backend.obj.dto.UserInfoDto;
import com.ht.web_vr_home_tour_backend.obj.enums.UserLevel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import java.time.LocalDateTime;

@Data
@TableName("user_info")

public class UserInfo {
    @TableId("id")
    @ApiModelProperty("用户id")
    Long id;

    @ApiModelProperty("用户名")
    @Length(min = 5, max = 100, message = "用户名错误")
    String username;

    @ApiModelProperty("用户密码SHA-256加密")
    String password;

    @ApiModelProperty("用户头像")
    String avatar;

    @ApiModelProperty("用户昵称")
    @Length(min = 5, max = 100, message = "昵称错误")
    String nickName;

    @ApiModelProperty("用户等级-权限控制")
    UserLevel level;

    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    LocalDateTime createTime;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    LocalDateTime updateTime;

    public UserInfo(){}

    public UserInfo(UserInfoDto userInfoDto) {
        this.id = Long.valueOf(userInfoDto.getId());
        this.username = userInfoDto.getUsername();
        this.password = null;
        this.avatar = userInfoDto.getAvatar();
        this.nickName = userInfoDto.getNickName();
        this.level = userInfoDto.getLevel();
    }
}
